home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / cshx86.zip / SAMPLES / CL.CSH < prev    next >
Text File  |  1993-04-28  |  7KB  |  232 lines

  1. #    Compile and link .c, .obj and/or .lib files for Windows NT, Release 2.1.d
  2. #    Copyright (c) 1992-1993 by Hamilton Laboratories.  All rights reserved.
  3.  
  4. #    If CPU == MIPS, either the old MIPS compiler or the new hybrid Microsoft/
  5. #    MIPS compiler may be used.  By default on NTVersion < 404 (not March beta),
  6. #    the old MIPS compiler is used; on NTVersion >= 404, the new compiler is
  7. #    the default.  You may explicitly specify old or new using the -old or
  8. #    -new options.
  9.  
  10. #    If CPU == ALPHA, either the old Alpha compiler or the new hybrid Microsoft/
  11. #    DEC compiler may be used.  By default on NTVersion < 404 (not March beta),
  12. #    the old ALPHA compiler is used; on NTVersion >= 404, the new compiler is
  13. #    the default.  You may explicitly specify old or new using the -old or
  14. #    -new options.
  15.  
  16. #    By default, cl will compile and link using the following options:
  17.  
  18. #        i386 Compile:        -c -Od -Zi -W4 -DNT -Di386=1 -D_X86_=1 -DWIN32
  19. #                                -Dend=EndOfData
  20.  
  21. #        MIPS Compile:
  22. #            using MIPS:        -c -std -O -o $i:b.obj -EL -DNT -DMIPS=1 -D_MIPS_=1
  23. #                                -DWIN32 -Dend=EndOfData
  24. #            using new MS:    -c -Od -Zi -W4 -DNT -DMIPS=1 -D_MIPS_=1 -DWIN32
  25. #                                -Dend=EndOfData
  26.  
  27. #        ALPHA Compile:
  28. #            using DEC:        -c -std -G 0 -o $i:b.obj -checkstack 4096 -01 -EL
  29. #                                -Dend=EndOfData -DNT -DALPHA=1 -DWIN32 -excpt -DDEVL=1
  30. #                                -I<include directories>
  31. #            using new MS:    -c -Od -Zi -W4 -DNT -DALPHA=1 -D_ALPHA_=1 -DWIN32
  32. #                                -Dend=EndOfData -D__stdcall= -D_cdecl=
  33.  
  34. #        Link:                    -subsystem:console -entry:mainCRTStartup -debug:full
  35. #                                -debugtype:both
  36.  
  37. #    All the output is filtered thru ferr which filters out nuisance
  38. #    error messages such as the warnings about no modules extracted from
  39. #    a given .lib file or about assignments inside conditional tests.
  40. #    The list of nuisance messages is kept in skip file pointed to by the
  41. #    skip variable.  If skip isn't set or doesn't point to a real file, cl.csh
  42. #    wil attempt to look for a skip file in the same directory with this
  43. #    script.
  44.  
  45. if (! $?skip || ! -e $skip) then
  46.     #    Look for the filter file in the same directory with this cl.csh script.
  47.     set s = `whereis cl.csh`
  48.     if ($#s && -e $s[0]:h\skip) then
  49.         set skip = $s[0]:h\skip
  50.         alias ferr fgrep -vqf $skip
  51.     else
  52.         echo -2 Warning:  Output filter file not found!  No filtering will be done.
  53.         alias ferr cat
  54.     end
  55. else
  56.     alias ferr    fgrep -vqf $skip
  57. end
  58.  
  59. proc cl(args)
  60.     local i, j, ^
  61.             debug, c_only, O_opt, options, ^
  62.             c_files, obj_files, lib_files, exe, ldir, stdlibs, ^
  63.             use_old_cc, linker
  64.  
  65.     switch (CPU)
  66.         case "MIPS":
  67.             @ use_old_cc = NTVersion < 404
  68.             @ O_opt = ""
  69.             break
  70.         case "ALPHA":
  71.             @ use_old_cc = NTVersion < 404
  72.             @ O_opt = "-O1"
  73.             break
  74.         default:
  75.             @ O_opt = "-Od"
  76.     end
  77.  
  78.     @ c_only = 0
  79.     for i = 0 to $#args - 1 do
  80.         @ j = substr(args[i], 1, 1)
  81.         if (j == '-' || j == '/') then
  82.             if (substr(args[i], 2) == 'c') then
  83.                 @ c_only = 1
  84.             else
  85.                 if (substr(args[i], 2, 1) == 'O') then
  86.                     set Oopt = $args[i]
  87.                 else
  88.                     if (CPU != "i386" && substr(args[i], 2) == "old") then
  89.                         @ use_old_cc = 1
  90.                     else
  91.                         if (CPU != "i386" && substr(args[i], 2) == "new") then
  92.                             @ use_old_cc = 0
  93.                         else
  94.                             set options = $options $args[i]
  95.                         end
  96.                     end
  97.                 end
  98.             end
  99.         else
  100.             switch ($args[i]:e)
  101.                 case 'c':
  102.                     set c_files = $c_files $args[i]
  103.                     set obj_files = $obj_files $args[i]:b.obj
  104.                     break
  105.                 case 'obj':
  106.                     set obj_files = $obj_files $args[i]
  107.                     break
  108.                 case 'exe':
  109.                     set exe = $args[i]
  110.                     break
  111.                 case 'lib':
  112.                 default:
  113.                     set lib_files = $lib_files $args[i]
  114.             end
  115.         end
  116.     end
  117.  
  118.     #    Run the compile step on each .c file.
  119.     (switch (CPU)
  120.         case "MIPS":
  121.             if (use_old_cc) then
  122.                 foreach i ($c_files)
  123.                     echo cc -c -std -O -o $i:b.obj -EL -DNT -DMIPS=1 -D_MIPS_=1 ^
  124.                             -DWIN32 -Dend=EndOfData $options $i
  125.                     cc -c -std -O -o $i:b.obj -EL -DNT -DMIPS=1 -D_MIPS_=1 ^
  126.                             -DWIN32 -Dend=EndOfData $options $i
  127.                     if ($status) return
  128.                     echo mip2coff $i:b.obj
  129.                     mip2coff $i:b.obj
  130.                     if ($status) return
  131.                 end
  132.             else
  133.                 foreach i ($c_files)
  134.                     echo mcl -c $O_opt -Zi -W4 -DNT -DMIPS=1 -D_MIPS_=1 -DWIN32 ^
  135.                             -Dend=EndOfData $options $i
  136.                     mcl -c $O_opt -Zi -W4 -DNT -DMIPS=1 -D_MIPS_=1 -DWIN32 ^
  137.                             -Dend=EndOfData $options $i
  138.                     if ($status) return
  139.                 end
  140.             end
  141.             break
  142.  
  143.         case "ALPHA":
  144.             if (use_old_cc) then
  145.                 #    Alpha compiler doesn't handle the INCLUDE environment variable
  146.                 #    properly -- it has to be passed on the command line.
  147.                 set Inc = -I$INCLUDE:gs/;/ -I/
  148.                 if (NTVersion < 404) set options = -EL -excpt -DDEVL=1 $options
  149.                 foreach i ($c_files)
  150.                     echo acc -c -std -G 0 -o $i:b.obj -checkstack 4096            ^
  151.                             $O_opt -Dend=EndOfData -DNT -DALPHA=1 -D_ALPHA_=1    ^
  152.                             -DWIN32 $options $Inc $i
  153.                     acc -c -std -G 0 -o $i:b.obj -checkstack 4096                ^
  154.                             $O_opt -Dend=EndOfData -DNT -DALPHA=1 -D_ALPHA_=1    ^
  155.                             -DWIN32 $options $Inc $i
  156.                     if ($status) return
  157.                     echo a2coff $i:b.obj
  158.                     a2coff $i:b.obj
  159.                     if ($status) return
  160.                 end
  161.             else
  162.                 foreach i ($c_files)
  163.                     echo claxp -c $O_opt -Zi -W4 -DNT -DALPHA=1 -D_ALPHA_=1    ^
  164.                             -DWIN32 -Dend=EndOfData -D__stdcall= -D_cdecl=        ^
  165.                             $options $i
  166.                     claxp -c $O_opt -Zi -W4 -DNT -DALPHA=1 -D_ALPHA_=1 -DWIN32 ^
  167.                             -Dend=EndOfData -D__stdcall= -D_cdecl= $options $i
  168.                     if ($status) return
  169.                 end
  170.             end
  171.             break
  172.  
  173.         default:
  174.             foreach i ($c_files)
  175.                 echo cl386 -c $O_opt -Zi -W4 -DNT -Di386=1 -D_X86_=1 -DWIN32 ^
  176.                         -Dend=EndOfData $options $i
  177.                 cl386 -c $O_opt -Zi -W4 -DNT -Di386=1 -D_X86_=1 -DWIN32 ^
  178.                         -Dend=EndOfData $options $i
  179.                 if ($status) return
  180.             end
  181.     end
  182.  
  183.     if (! $c_only) then
  184.  
  185.         #    If no .exe file was specified, name the output to match the
  186.         #    first .c or .obj file on the command line.
  187.         if (exe == '') then
  188.             @ exe = $#c_files == 0 ? $obj_files[0]:b.exe : $c_files[0]:b.exe
  189.         end
  190.  
  191.         if (NTVersion >= 404) then
  192.  
  193.             set linker = link32
  194.             set stdlibs = libcmt.lib ntdll.lib kernel32.lib
  195.  
  196.         else
  197.  
  198.             #    Figure out where libcmt.lib lives on the LIB path.
  199.             if (LIB =~ "*;*") then
  200.                 foreach i ($LIB:gs/;/ /)
  201.                     if (-e $i\libcmt.lib) then
  202.                         @ ldir = i
  203.                         break;
  204.                     else
  205.                         if (CPU == "ALPHA" && -e $i\alpha\libcmt.lib) then
  206.                             set ldir = $i\alpha
  207.                         end
  208.                     end
  209.                 end
  210.             else
  211.                 @ ldir = LIB
  212.             end
  213.  
  214.             set linker = coff -link
  215.  
  216.             if (CPU == "ALPHA") then
  217.                 set stdlibs = $ldir\libcmt.lib $ldir\ntdll.lib $ldir\kernel32.lib
  218.             else
  219.                 set stdlibs = $ldir\libcmt.lib $ldir\^*.lib
  220.             end
  221.         end
  222.  
  223.         #    Run the link step, assuming it's a console app with debug info.
  224.         echo $linker -subsystem:console -entry:mainCRTStartup -debug:full    ^
  225.             -debugtype:both -out:$exe $obj_files $lib_files "$stdlibs"
  226.         $linker -subsystem:console -entry:mainCRTStartup -debug:full        ^
  227.             -debugtype:both -out:$exe $obj_files $lib_files $stdlibs
  228.     end) | ferr
  229. end
  230.  
  231. cl $argv
  232.